package com.baidu.roomdemo.fragment

import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.baidu.roomdemo.adapter.UserAdapter
import com.baidu.roomdemo.databinding.FragmentHomeBinding
import com.baidu.roomdemo.databinding.FragmentListBinding
import com.baidu.roomdemo.viewmodel.MainViewModel

class ListFragment:BaseFragment<FragmentListBinding>() {
    private val mViewModel: MainViewModel by activityViewModels()
    private val mAdapter = UserAdapter()

    override fun initBinding(): FragmentListBinding {
        return FragmentListBinding.inflate(layoutInflater)
    }

    override fun initView() {
        mViewModel.userList.observe(this){
            //将数据显示到recyclerView上
            mAdapter.setData(it)
        }

        //配置recyclerView
        mBinding.recyclerView.adapter = mAdapter
        mBinding.recyclerView.layoutManager = LinearLayoutManager(
            requireContext(),
            LinearLayoutManager.VERTICAL,
            false
        )
    }
}






